﻿using SD.Common;
using SD.Toolkits.Mapper;
using SlamDunk.MES.Domain.Entities.FoundationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.FoundationContext;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Maps
{
    /// <summary>
    /// 基础定义相关映射
    /// </summary>
    public static class FoundationMap
    {
        #region # 工厂模型映射 —— static FacilityInfo ToDTO(this Facility facility)
        /// <summary>
        /// 工厂模型映射
        /// </summary>
        public static FacilityInfo ToDTO(this Facility facility)
        {
            FacilityInfo facilityInfo = facility.Map<Facility, FacilityInfo>();
            facilityInfo.ParentNodeId = facility.ParentNode?.Id;

            return facilityInfo;
        }
        #endregion

        #region # 工位映射 —— static WorkStationInfo ToDTO(this WorkStation...
        /// <summary>
        /// 工位映射
        /// </summary>
        public static WorkStationInfo ToDTO(this WorkStation workStation, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            WorkStationInfo workStationInfo = workStation.Map<WorkStation, WorkStationInfo>();
            workStationInfo.FacilityInfo = workStation.FacilityId.HasValue
                ? facilityInfos?[workStation.FacilityId.Value]
                : null;

            return workStationInfo;
        }
        #endregion

        #region # 计量单位组映射 —— static MeasureUnitGroupInfo ToDTO(this MeasureUnitGroup unitGroup)
        /// <summary>
        /// 计量单位组映射
        /// </summary>
        public static MeasureUnitGroupInfo ToDTO(this MeasureUnitGroup unitGroup)
        {
            MeasureUnitGroupInfo unitGroupInfo = unitGroup.Map<MeasureUnitGroup, MeasureUnitGroupInfo>();
            unitGroupInfo.MasterUnitInfo = unitGroup.MasterUnit.ToDTO();

            return unitGroupInfo;
        }
        #endregion

        #region # 计量单位映射 —— static MeasureUnitInfo ToDTO(this MeasureUnit measureUnit)
        /// <summary>
        /// 计量单位映射
        /// </summary>
        public static MeasureUnitInfo ToDTO(this MeasureUnit measureUnit)
        {
            MeasureUnitInfo unitInfo = measureUnit.Map<MeasureUnit, MeasureUnitInfo>();
            unitInfo.MasterCoefficient?.Revise();
            return unitInfo;
        }
        #endregion
    }
}
